package com.mutual.reins.danger.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.danger.entity.PrptDangerItem;
import com.mutual.reins.danger.mapper.PrptDangerItemMapper;
import com.mutual.reins.danger.service.IPrptDangerItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CodeGenerate
 * @since 2021-03-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PrptDangerItemServiceImpl extends ServiceImpl<PrptDangerItemMapper, PrptDangerItem> implements IPrptDangerItemService {



    /**
     * 获取该对象Map（key：投保单号—危险单位号 value：PrptDangerUnit）
     *
     * @param queryWrapper 查询条件
     * @return 获取该对象Map
     */
    @Override
    public Map<String, List<PrptDangerItem>> selectPrptDangerItemMap(QueryWrapper queryWrapper) {
        List<PrptDangerItem> prptDangerItemList = this.list(queryWrapper);
        Map<String,List<PrptDangerItem>> prptDangerItemMap = new HashMap<>(16);
        if(ObjectUtil.isNotNull(prptDangerItemList) && !prptDangerItemList.isEmpty()){
            for(PrptDangerItem prptDangerItem:prptDangerItemList){
                if(prptDangerItemMap.containsKey(prptDangerItem.getProposalNo()+"-"+prptDangerItem.getDangerNo())){
                    List<PrptDangerItem> prptDangerItemMapList = prptDangerItemMap.get(prptDangerItem.getProposalNo()+"-"+prptDangerItem.getDangerNo());
                    prptDangerItemMapList.add(prptDangerItem);
                }else{
                    List<PrptDangerItem> prptDangerItemMapList = new ArrayList<>();
                    prptDangerItemMapList.add(prptDangerItem);
                    prptDangerItemMap.put(prptDangerItem.getProposalNo()+"-"+prptDangerItem.getDangerNo(),prptDangerItemMapList);
                }
            }
        }
        return prptDangerItemMap;
    }
}
